package com.neusoft.Shixun.controller;

import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.redisdao.RedisDao;
import com.neusoft.Shixun.service.impl.RedisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@CrossOrigin("*")
@RequestMapping("/RedisController")
public class RedisController {
    @Autowired
    private RedisServiceImpl redisServiceImpl;

    @PostMapping("/saveNotTimeLimit")
    public ResponseBean<String> saveNotTimeLimit(String key, String value) {
        redisServiceImpl.set(key, value);
        return new ResponseBean<>("success");
    }

    @PostMapping("/saveTimeLimit")
    public ResponseBean<String> saveTimeLimit(String key, String value) {
//        暂时先设置成50s
        redisServiceImpl.set(key, value, 50, TimeUnit.SECONDS);
        return new ResponseBean<>("success");
    }

    @GetMapping("/read")
    public ResponseBean<String> read(String key) {
        return redisServiceImpl.get(key);
    }
}
